/*!
 * \autor captainpeng
 * \date 2019-12-17
 * \version 1.0
 * \copyright
 */

#include<iostream>
#include<my.hpp>
#include"memory/memMark.hpp"
#include"memory/memSplayTree.hpp"

void Free(void * val){
    std::cout<<"Free "<<val<<std::endl;
    my::memFunc<int>::Free(val);
}

int main(){
    using namespace std;
    using namespace my;
    
    memSplayTree t;
    void * tmp = t.insert(1, sizeof(int), 1, memMark::COUNTMARK, memFunc<int>::Alloc, Free);
    t.print();
    std::cout<<"-----"<<std::endl;
    void * tmp1 = t.insert(1, sizeof(int), 1, memMark::COUNTMARK, memFunc<int>::Alloc, Free);
    t.print();
    std::cout<<"-----"<<std::endl;
    void * tmp2 = t.insert(1, sizeof(int), 1, memMark::COUNTMARK, memFunc<int>::Alloc, Free);
    t.print();
    std::cout<<"-----"<<std::endl;
    void * tmp3 = t.insert(1, sizeof(int), 1, memMark::COUNTMARK, memFunc<int>::Alloc, Free);
    t.print();
    std::cout<<"-----"<<std::endl;
    void * tmp4 = t.insert(1, sizeof(int), 1, memMark::COUNTMARK, memFunc<int>::Alloc, Free);
    t.print();
    std::cout<<"find tmp "<<tmp<<" -----"<<std::endl;
    t.find(tmp);
    t.print();
    std::cout<<"find tmp2 "<<tmp2<<" -----"<<std::endl;
    t.find(tmp2);
    t.print();
    std::cout<<"find tmp3 "<<tmp3<<" -----"<<std::endl;
    t.find(tmp3);
    t.print();
    std::cout<<"find tmp4 "<<tmp4<<" -----"<<std::endl;
    t.find(tmp4);
    t.print();

    std::cout<<"---- each_print begin ----"<<std::endl;
    t.each_print();
    std::cout<<"---- each_print end ----"<<std::endl;

    std::cout<<"---- free by mark begin ----"<<std::endl;
    t.freeByMark(memMark::COUNTMARK);
    t.print();
    std::cout<<"---- free by mark end ----"<<std::endl;
    
    void * tmp5 = t.insert(10, sizeof(int), 1, memMark::COUNTMARK, memFunc<int>::Alloc, Free);
    t.find(tmp1);
    std::cout<<"find tmp5+6 "<<tmp5+6<<" -----"<<std::endl;
    t.find(tmp5+6);
    t.print();

    // std::cout<<"erase tmp2 "<<tmp2<<" -----"<<std::endl;
    // t.erase(tmp2);
    // t.print();
    std::cout<<"free -----"<<std::endl;
    t.free();
    return 0;
}
